<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Benchmark: how fast is creating *N* DOM nodes?</title>
    <script type="text/javascript" src="benchmarker.js"></script>
    <script type="text/javascript">
/* <![CDATA[ */
new Benchmarker(
  {
    clone: function() {
      for (var i = 0; i < nodes; i++)
        wrap.appendChild(nodeREF.cloneNode(true));
    },
    html: function() {
      var html = '';
      for (var i = 0; i < nodes; i++)
        html += nodeHTML;
      wrap.innerHTML = html;
    },
    fragment: function() {
      var d = document.createDocumentFragment();
      for (var i = 0; i < nodes; i++)
        d.appendChild(nodeREF.cloneNode(true));
      wrap.appendChild(d);
    },
    fragments: function() {
      var d = document.createDocumentFragment();
      for (var i = 0; i < nodes/frag_parts; i++)
        d.appendChild(nodeREF.cloneNode(true));
      for (var i = 0; i < frag_parts; i++)
        wrap.appendChild(d.cloneNode(true));
    }
  },
  {
    iterations: 10,
    afterTest: function() {
      wrap.innerHTML = '';
    },
    setup: function() {
      nodes    = 1000;
      frag_parts = 10;
      nodeHTML = "<div><strong>foo</strong> bar <em>baz</em></div>";
      wrap     = $T('div', document.body);
      wrap.hide();
      nodeREF  = $T('div', {innerHTML: nodeHTML}).firstChild;
    }
  }
);
/* ]]> */
    </script>
  </head>
  <body>
  </body>
</html>
